package com.test.Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.test.daoImp.WriteDaoImp;
import com.test.entity.WriteEntity;
//添加用例
/**
 * Servlet implementation class Article_in
 */
@WebServlet("/com/test/servlet/Article_in_servlet")
public class Article_in_servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public Article_in_servlet() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		System.out.println("前端获取文章数据----");
//		String text = request.getParameter("text");
		int id = Integer.parseInt(request.getParameter("count"));
//		String id  = request.getParameter("count");
		String text = request.getParameter("t1");
		String title = request.getParameter("article_title");
		String name = request.getParameter("name");
		String type = request.getParameter("type");
		String expectResults = request.getParameter("expectResults");
		String actualResults = request.getParameter("actualResults");
		System.out.println("将数据保存在实体类中  text"+text+title+type);
		
		//将数据装入数据实体
		WriteEntity data = new WriteEntity();
		
		data.setId(id);
		data.setTitle(title);
		data.setType(type);
		data.setName(name);
		data.setText(text);
		data.setExpectResults(expectResults);
		data.setActualResults(actualResults);
		
		WriteDaoImp ri = new WriteDaoImp();
		boolean flag = ri.in_tb_article_info(data);
		// 调用数据访问层  写入数据库
		if(flag) {
			
			// 发表成功
//			request.getRequestDispatcher("").forward(request,response);
			response.sendRedirect("/Test_Project/findServlet.do");
			System.out.println("添加用例成功");
		}else {
			response.sendRedirect("/Test_Project/write.jsp");
			System.out.println("添加用例失败....");
		}
	

	}


}
